import axios from 'axios';
import NProgress from 'nprogress'; // 进度条
import 'nprogress/nprogress.css'; // 进度条样式
import Vue from "vue";
var vo = new Vue();

const instance = axios.create({
    baseURL:'http://39.103.187.89:80',
    // baseURL:'http://localhost:8080',
    timeout:4000
})

instance.interceptors.request.use(config=>{
    NProgress.start()
    return config;
},error => {
    return Promise.reject(error)
})

instance.interceptors.response.use(resp=>{
    NProgress.done()
    return resp;
},error => {
    NProgress.done()
    const errResp = error.response
    errorHandler(errResp)
    return Promise.reject(error)
})

const errorHandler = ({data,status})=>{
    if (status===500 || status === 400){
        vo.$breadstick.notify('❌'+(data==undefined?"服务器异常!!":data))
    }
}

export default instance;

